chmod 777 or 755? Learn to use chmod Command with Examples | 您所在的位置:网站首页 › chmod read only file system › chmod 777 or 755? Learn to use chmod Command with Examples |
File Properties Commands
chmod Command Examples
This article will teach you how to change permissions in Linux with practical examples of chmod command. Sooner or later in the Linux world, you will have to change the permission on a file or directory. This is done with the chmod command. In this article, I’ll share with you some of the practical examples of chmod command. I’ll also explain some the popular terms like chmod 777 or chmod 755 or chmod -r. Before you see the chmod examples, I would strongly advise you to learn the basics of file permissions in Linux. Using chmod command will be a lot easier once you understand the permissions. Chmod command in LinuxWhat is chmod? chmod stands for change mode. This command is used for changing the mode of access. But wait! Is it not meant for changing the permission? Actually, in early Unix days, permissions were called mode of access. This is why this particular command was named chmod. chmod command has the following syntax: chmod [option] mode fileBefore you see how to use chmod, you should know its options. -v : output a diagnostic for every file processed-c : like verbose but report only when a change is made–reference=FILE : use FILE’s mode instead of MODE values–R : change permissions recursivelyNote that using -v option report if change were made or if nothing needed to be done. When combined with -R option, -v can produce a lot of output. –reference=FILE let you use the current permission mode of FILE as the permissions to set on the target file. Note this option requires a double-dash prefix (–) not (-). Chmod command examplesUsing chmod command is very easy if you know what permissions you have to set on a file. For example, if you want the owner to have all the permissions and no permissions for the group and public, you need to set the permission 700 in absolute mode: chmod 700 filenameYou can do the same in symbolic mode. chmod u=rwx filenameIf you want an easy way to know the Linux file permission in numeric or symbolic mode, you can use this chmod calculator. Just select the appropriate permissions and it will tell you the permissions in both absolute and symbolic mode. Change permission on all the files in a directory recursivelychmod has the recursive option that allows you to change the permissions on all the files in a directory and its sub-directories. chmod -R 755 directorychmod 777: Everything for everyoneYou might have heard of chmod 777. This command will give read, write and execute permission to the owner, group and public. If you want to change the mode to 777, you can use the command like this: chmod 777 filenamechmod 777 is considered potentially dangerous because you are giving read, write and execute permission on a file/directory to everyone (who is on your system). You should totally avoid it. chmod +x or chmod a+x: Execution for everyoneProbably one of the most used case of chmod is to give a file the execution bit. Often after downloading an executable file you will need to add this permission before using it. To give owner, group and everyone else permission to execute file: chmod +x /path/to/filechmod 755: Only owner can write, read and execute for everyoneThis next command will set the following permission on file: rwxr-xr-x. Only the owner will be allowed to write to the file. Owner, group members and everyone else will have read and execute permission. chmod 755 /path/to/filechmod 700: Everything for owner onlyThis command will give read, write and execute permission to the owner. Group and others will have no permissions, not even read. chmod 700 /path/to/filechmod 666: No one executesTo give owner, group and everyone else read and write permission on file. chmod -c 666 /path/to/filechmod 644: Everyone can read, only owner can writeWith this next one, owner will have read and write while group and everyone else have read permission. chmod 644 /path/to/filechmod 600: Owner can read and write, nothing else for anyoneWith this next one, owner will have read and write while group and everyone else will have no permissions whatsoever. chmod 600 /path/to/fileLearn Linux Quickly - Linux Commands for BeginnersLearn Linux Quickly doesn’t assume any prior Linux knowledge, which makes it a perfect fit for beginners. Nevertheless, intermediate and advanced Linux users will still find this book very useful as it goes through a wide range of topics. Learn Linux Quickly will teach you the following topics:Insta…Gumroadchmod command examples in symbolic modeIn the above examples, I use bitmask to set the new MODE. Those are easy to calculate. Simple addition is required. Consider the following: X = 1W = 2R = 4You can now easily see where I got the 755, 666, 640 from. You don’t have to use bitmask to set new permission. A more human readable way is available. This second format looks like this: chmod OPTIONS {u,g,o}{+,-,=}{r,w,x} /path/to/fileWhile this may seem complicated, it is quite simple. You first start with typing chmod and the OPTIONS that you want. Then, ask yourself: Who am I changing permissions for? User, Group, Others. This will give you the first section of the command: chmod OPTIONS {u,g,o}The next step to complete the command, you either decide to add permissions bits (+), remove permissions (-), or set permission (=). This last one will add or remove permissions as needed to set permission as you requested. chmod -v u+The next section is where you decide the permission MODE to apply(+), remove (-) or match (=). You can specify any combination of rwx. chmod -v u+rwThis next example will apply read/write permission to file for the owner. The verbose option will cause chmod to report on the action. chmod -v u+rw /path/to/fileThis next one will set the group’s write permission on directory and all its content recursively. It will report only on changes. chmod -cR g+w /path/to/directoryYou can combine multiple operation to be done on permission like this next example. It will make sure owner has read/write/execute, also add write permission for group and remove execution for everyone else: chmod u=rwx,g+w,o-x /path/to/fileThis last one will use rFile as a reference to set permission on file. When completed, the permission of file will be exactly as they are for rFile chmod --reference=/path/to/rFile /path/to/fileThere are more options and MODE that can be used with chmod that are not covered or mentioned here. I wanted to keep this to basic and hopefully help a few new Linux user. A word of warning!With chmod and sudo you now have to power to change permission on almost any files. This does NOT mean you should. Permissions outside your home directory are set the way they are for a reason. Changing them is rarely the appropriate solutions to any problems. I hope these chmod command examples were helpful for you. Got a question or suggestion? Please leave a comment below. Previous Next Eric SimardLinux has been my passion for around 2 decades. I enjoy compiling 'Linux from Scratch'. Canada |
CopyRight 2018-2019 实验室设备网 版权所有 |